  
#include <WiFi.h>

const char* ssid     = "cohabit";
const char* password = "lewifidecohabit";

WiFiServer server(80);

int sensorValue=analogRead(A6);
void setup() {

  // initialize serial communication at 9600 bits per second:
  Serial.begin(115200);
    

    // We start by connecting to a WiFi network

    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    
    server.begin();
}


int value = 0;

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
   sensorValue = analogRead(A6);
  // Send the value you read to the site:
  

  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("New Client.");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);               // print it out the serial monitor

   if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
           client.println(html_document());

           

          

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
            } else {    // if you got a newline, then clear currentLine:
            currentLine = "";
          }
   
   }          else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
          }
    }

    
 // close the connection:
    client.stop();
    Serial.println("Client Disconnected.");


    }
    }

String html_document() {
  String sHTML;
  sHTML = "<!doctype html>";
  sHTML +="<html>";
  sHTML +="<html lang=\"de\">";
  /***************** head ****************/
  sHTML +="<head>";
  sHTML +="<meta http-equiv=\"refresh\" content=\"5\">";
  /****Valeur***/
  sHTML += "Le sensor affiche la valeur :             ";
  sHTML += String(sensorValue);
  sHTML += "                         Pourcentage de l'humidite est :         ";
  sHTML += String(sensorValue*(100.0/2400.0));
  return sHTML;
}


